package com.dawn.usermanage.action;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.dawn.usermanage.bean.SinaInfoBean;
import com.dawn.usermanage.bean.TwSinainfo;
import com.dawn.usermanage.bean.UserBean;
import com.dawn.usermanage.bean.UserPreference;
import com.dawn.usermanage.service.SinaUserMService;
import com.opensymphony.xwork2.ActionSupport;

@Controller("registerAction")
@Scope("prototype")
public class RegisterAction extends ActionSupport implements SessionAware {

 
    private static final long serialVersionUID = 4896220852536522687L;
    private static Logger logger = Logger.getLogger(RegisterAction.class);
    private UserBean userBean;
    private TwSinainfo sinaUserInfo;
 
	
 

	@Autowired
	private SinaUserMService sinaUserMService;

	private Map<String, Object> session;

	public String showSInfoAndReg() {

		String sinaId = session.get("sinaId").toString();
		String accessToken = (String) session.get("accToken");
		String accessTokenSecret = (String) session.get("accTokenSecret");
		sinaUserInfo = sinaUserMService.findSUserInfo(sinaId);
		if (sinaUserInfo == null) {
			sinaUserInfo = sinaUserMService.addSinaBasic(sinaId, accessToken,
					accessTokenSecret);
		}
		return sinaUserInfo == null ? ERROR : SUCCESS;
	}

	public String register() {
		userBean = sinaUserMService.addUserInfo(userBean);
		if (userBean == null)
			return ERROR;
		return SUCCESS;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
    

	public UserBean getUserBean() {
		return userBean;
	}

	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}

	public TwSinainfo getSinaUserInfo() {
		return sinaUserInfo;
	}

 
   
	
 
    public void setSinaUserInfo(TwSinainfo sinaUserInfo) {
        this.sinaUserInfo = sinaUserInfo;
    }
 
}
